package com.example.controller;

import com.example.po.Admin;
import com.example.service.AdminService;
import com.example.vo.AdminVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpSession;

/**
 * @auter czcjq
 * @date 2022/5/18 11:49
 */
@RequestMapping("/admin")
@ResponseBody
public class AdminController {
    @Autowired
    private AdminService adminService;

    @RequestMapping(value = "/adminlogin",method = RequestMethod.POST)

    public AdminVo lpogin(String atel, String apassword, HttpSession session){
        Admin login = adminService.login(atel, apassword);
        AdminVo adminVo = new AdminVo();
        if(login!=null){
            adminVo.setCode(1);
            adminVo.setMsg("登陆成功");
            session.setAttribute("login",login);
        } else {
            adminVo.setCode(0);
            adminVo.setMsg("账户名或者密码错误");
        }
        System.out.println("管理员登陆成功"+adminVo);
        return adminVo;
    }
}
